<?php
$err=validation($_POST);
extract($_POST);
date_default_timezone_set('UTC');
$created=date("d/m/Y-H:i:s");
if($err=="success" && empty($_SESSION['userInfo']['invitationType']))
{
	$random_string=md5(date("dmYHis"));
	$dbQ="INSERT INTO 
			`user` (`name`, `email`, `password`,`status`, `created`, `image`, `email_confirm`) 
			VALUES ('$name', '".strtolower($email)."', '".md5($password)."', 'Y', '$created', './profileImage/face.JPG', '$random_string')";
			
	@mysql_query($dbQ);
	
	$headers = 'From: dofollowbookmark@gmail.com' . "\r\n" .
			   'Reply-To: dofollowbookmark@gmail.com' . "\r\n";
	$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
	$subject='DoFollowBookmark - Confirm registration';
	$body="Dear $name,<br /> Welcome to DoFollowBookmark. To activate your account please click on this link below.<br />";
	$body.=serverPath()."completeRegistration.php?auth=".$random_string.":::".strtolower($email);
	
	mail(strtolower($email), $subject, $body, $headers);
}
elseif($err=='Notcompleted' && empty($_SESSION['userInfo']['invitationType']))
{
	$random_string=md5(date("dmYHis"));
	$dbQ="UPDATE `user` 
		SET 
		`name`='$name',
		`password`='".md5($password)."',
		`status`='Y', 
		`created`='$created', 
		`image`='./images/face.JPG', 
		`email_confirm`='$random_string' WHERE `email`='".strtolower($email)."'";
	@mysql_query($dbQ) or die(mysql_error());
	
	$headers = 'From: dofollowbookmark@gmail.com' . "\r\n" .
				'Reply-To: dofollowbookmark@gmail.com' . "\r\n";
	$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
	$subject='DoFollowBookmark - Confirm registration';
	$body="Dear $name,<br /> Welcome to DoFollowBookmark. To activate your account please click on this link below.<br />";
	$body.=serverPath()."completeRegistration.php?auth=".$random_string.":::".strtolower($email);
	
	mail(strtolower($email), $subject, $body, $headers);
}

elseif($err=="success" && !empty($_SESSION['userInfo']['invitationType']))
{
	$dbQ="INSERT INTO 
			`user` (`name`, `email`, `password`,`status`, `created`, `image`, `email_confirm`) 
			VALUES ('$name', '".strtolower($email)."', '".md5($password)."', 'Y', '$created', './profileImage/face.JPG', 'Y')";
	@mysql_query($dbQ);
	$InsertedId=mysql_insert_id();
	@mysql_query("INSERT INTO `network` (`uid`, `fid`, `friendship`) VALUES('$InsertedId', '".$_SESSION['userInfo']['invitationType']['InvEmailFrom']."', 'accepted')") or die(mysql_error());
	@mysql_query("INSERT INTO `network` (`uid`, `fid`, `friendship`) VALUES('".$_SESSION['userInfo']['invitationType']['InvEmailFrom']."', '$InsertedId', 'accepted')") or die(mysql_error());
	
	$headers = 'From: dofollowbookmark@gmail.com' . "\r\n" .
			   'Reply-To: dofollowbookmark@gmail.com' . "\r\n";
	$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
	$subject='DoFollowBookmark - Confirm registration';
	$body="Dear $name,<br /> Welcome to DoFollowBookmark. Start bookmarking and build your network.<br />";
	
	mail(strtolower($email), $subject, $body, $headers);
	unset($_SESSION['userInfo']);
	$_SESSION['userInfo']['email']=$email;
	$_SESSION['userInfo']['uid']=$InsertedId;
	$_SESSION['userInfo']['origUID']=$InsertedId;
	$_SESSION['userInfo']['name']=$name;
}
?>